package com.css.fxfzaqbz.modules.supergraph.repository.impl;

import com.css.fxfzaqbz.modules.supergraph.entity.EmergcyShelter;
import com.css.fxfzaqbz.modules.supergraph.repository.EmergcyShelterRepository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class EmergcyShelterRepositoryImpl implements EmergcyShelterRepository {
    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    @Resource
    private JdbcTemplate jdbcTemplate;
    @Override
    public void save(EmergcyShelter emergcyShelter) {
        String sql = "insert into sys_emergcy_shelter  values (:id,:name,:longitude,:latitude,:shelterClass,ST_GeometryFromText(:geom,4490),:delFlag,:dataVersion)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(emergcyShelter);
        //拿到新插入的主键值（i）
        KeyHolder keyHolder = new GeneratedKeyHolder();
        int i = namedParameterJdbcTemplate.update(sql, source, keyHolder);
    }

    @Override
    public void delete(String dataVersion) {
        String sql = "delete from sys_emergcy_shelter where data_version='"+dataVersion+"'";
        jdbcTemplate.update(sql);
    }
}
